package com.lx.designPattern.singleton;

import com.lx.designPattern.factory.BeanFactory;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2022-02-24 11:55:28
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2022-02-24     张李鑫                     1.0         1.0 Version
 */
public class Singleton {

    public static class Singleton1 {
        private static BeanFactory.Teacher instance = new BeanFactory.Teacher();

        public static BeanFactory.Teacher getInstance() {
            return instance;
        }
    }


    public static class Singleton2 {
        private static BeanFactory.Teacher instance;

        public static BeanFactory.Teacher getInstance() {
            if (instance != null) {
                return instance;
            }
            return new BeanFactory.Teacher();
        }
    }

    public static class Singleton3 {
        private volatile static BeanFactory.Teacher instance;

        public static BeanFactory.Teacher getInstance() {
            if (instance == null) {
                synchronized (instance) {
                    if (instance == null) {
                        return new BeanFactory.Teacher();
                    }
                }
            }
            return instance;
        }
    }


}
